package cn.doourbest.learnspring.service.impl;

import cn.doourbest.learnspring.dao.LearnSpringMapper;
import cn.doourbest.learnspring.service.LearnSpringService;
import jdk.nashorn.internal.objects.annotations.Constructor;
import org.apache.ibatis.annotations.ConstructorArgs;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.transaction.support.DefaultTransactionDefinition;
import org.springframework.transaction.support.DefaultTransactionStatus;
import org.springframework.transaction.support.SimpleTransactionStatus;

public class LearnSpringServiceImpl implements LearnSpringService {



    private LearnSpringMapper learnSpringMapper;

    @Autowired
    private PlatformTransactionManager platformTransactionManager;

    @Transactional
    public void getName() {

//        // 事务定义
//        DefaultTransactionDefinition def = new DefaultTransactionDefinition();
//        // 设置事务的传播行为
//        def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
//        // 开启事务并获取事务状态
//        TransactionStatus status = platformTransactionManager.getTransaction(def);
//
        System.out.println(learnSpringMapper.getDataSource("~!@#$%^&**)("));
        System.out.println(learnSpringMapper.getDataSource("~!@#$%^&**)("));
        System.out.println(learnSpringMapper.getDataSource("~!@#$%^&**)("));
//
//        learnSpringMapper.updateInfo();
//
//        platformTransactionManager.commit(status);
//
//        System.out.println(learnSpringMapper.getDataSource());
    }


    @Override
    @Transactional(propagation= Propagation.REQUIRES_NEW)
    public void getAge(ServiceBO serviceBO){
        System.out.println("7777");
    }


    public void setLearnSpringMapper(LearnSpringMapper learnSpringMapper) {
        this.learnSpringMapper = learnSpringMapper;
    }
}
